﻿Imports System
Imports System.Data.SqlClient
Imports System.Data

Public Class Cart
    Inherits System.Web.UI.Page

    'Open the connection to the database
    'Dim connectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=CIS441WinterParkWeb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
    Dim connectionString As String = "Data Source=SHANK-PC\SQLEXPRESS;Initial Catalog=WinterPark;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
    Dim connection As New SqlConnection(connectionString)
    Dim com As SqlCommand
    Dim str As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' get the next available transaction number
        Dim TransactionTableDataSet As New DataSet
        Dim selectTransactionStatement As String = "SELECT * from TransactionTable"
        Dim TransactionDataAdapter As New SqlDataAdapter(selectTransactionStatement, connection)
        TransactionDataAdapter.Fill(TransactionTableDataSet, "TransactionTable")
        Dim count As Integer = TransactionTableDataSet.Tables("TransactionTable").Rows.Count
        Dim dr As DataRow
        dr = TransactionTableDataSet.Tables("TransactionTable").Rows(count - 1)
        Dim TransactionId As String = dr("SalesOrdersId") + 1

        Dim CustomerCartDataSet As New DataSet
        Dim selectCustomerCartStatement As String = "Select * from CustomerCart"
        Dim CustomerCartDataAdapter As New SqlDataAdapter(selectCustomerCartStatement, connection)
        CustomerCartDataAdapter.Fill(CustomerCartDataSet, "CustomerCart")
        Dim Cartdr As DataRow
        For Each Cartdr In CustomerCartDataSet.Tables("CustomerCart").Rows
            ListBox1.Items.Add(Cartdr("ItemType"))
            ListBox1.Items.Add(Cartdr("ItemKind"))
            ListBox1.Items.Add(Cartdr("Price"))
        Next
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' add the new transaction data to the database
        '  Dim InsertTransactionStatement As String = "INSERT INTO TransactionTable VALUES ('" & _
        '      CustomerId & "', '" & _
        '     Surname & "', '" & _
        '    FirstName & "', '" & _
        '   MiddleName & "', '" & _
        '  Street & "', '" & _
        ' City & "', '" & _
        'State & "', '" & _
        'ZipCode & "', '" & _
        '                       Phone & "', '" & _
        '                      BirthDate & "', '" & _
        '                     EmailAddress & "', '" & _
        '                    EmergencyContact & "', '" & _
        '                   ECPhone & "')"
    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim cust As String = Session("CustomerID")
        
        'delete from the temp cart
        str = "delete from CustomerCart where CustomerID=" & cust
        ' Update tableName set FieldName1=" & value1 & ",FeildName2='" & value2 & "' where  CustomerID=" & cust
        Using conn As New SqlConnection(connectionString)
            Using cmd As New SqlCommand(str, conn)
                conn.Open()
                cmd.ExecuteNonQuery()
                conn.Close()
            End Using
        End Using
    End Sub
End Class